package gameAppLayer.gui;

import gameAppLayer.stateMachine.EGameStates;
import gameAppLayer.stateMachine.GameStateMachine;

import java.util.HashMap;

import com.jme3.asset.AssetManager;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;

/*
 * Listens for events from GUI or possibly Game, transitions between GUIStates
 */
public class GUIStateMachine {
	
	private GameStateMachine gameStateMachine;
	private EGameStates gameState;
	private Screen screen;
	private Nifty nifty;
	private AssetManager assetManager;
	
	private HashMap<String, Screen> screens = new HashMap<String, Screen>();
	
	public GUIStateMachine(AssetManager assetManager) {
		this.assetManager = assetManager;
	}
	
	//Defaults to main menu
	public void start(GameStateMachine gameStateMachine, Nifty nifty) {
		this.gameStateMachine = gameStateMachine;		
		this.gameState = gameStateMachine.getStateID();		
		this.nifty = nifty;
		
		buildGUIs(gameStateMachine.getStateID());		
	}
	
	public void swapState(String nextScreen) {
		nifty.gotoScreen(nextScreen);
		
		
	}
	
	public void buildGUIs(EGameStates gameState) {
		
		System.out.println("GameState = " + gameState.toString());
		
		if (gameState.equals(EGameStates.MENU)) {
			//Initialize MainMenu-related GUIS via factories
			
			
			
			
			
			Screen mainMenuScreen,
				loadGameScreen,
				saveGameScreen,
				optionsScreen,
				aboutScreen,
				tutorialScreen,
				modScreen,
				
				stateSetupScreen,
				universeSetupScreen,
				customCultureScreen,
				customReligionScreen,
				customGalaxyScreen;
			
			mainMenuScreen = new FGUIMainMenu().createScreen(nifty);
			nifty.addScreen(mainMenuScreen.getScreenId(), mainMenuScreen);
			//screens.put(mainMenuScreen.getScreenId(), mainMenuScreen);
			
			loadGameScreen = new FGUILoadGame().createScreen(nifty);
			nifty.addScreen(loadGameScreen.getScreenId(), loadGameScreen);
			
			//saveGameScreen = new FGUISaveGame().createScreen(nifty);
			//nifty.addScreen(saveGameScreen.getScreenId(), saveGameScreen);
			
			optionsScreen = new FGUIOptions().createScreen(nifty);
			nifty.addScreen(optionsScreen.getScreenId(), optionsScreen);
			
			aboutScreen = new FGUIAbout().createScreen(nifty);
			nifty.addScreen(aboutScreen.getScreenId(), aboutScreen);
			
			tutorialScreen = new FGUITutorial().createScreen(nifty);
			nifty.addScreen(tutorialScreen.getScreenId(), tutorialScreen);
			
			modScreen = new FGUIMods().createScreen(nifty);
			nifty.addScreen(modScreen.getScreenId(), modScreen);
			
			stateSetupScreen = new FGUIStateSetup().createScreen(nifty);
			nifty.addScreen(stateSetupScreen.getScreenId(), stateSetupScreen);
			
			universeSetupScreen = new FGUIUniverseSetup().createScreen(nifty);
			nifty.addScreen(universeSetupScreen.getScreenId(), universeSetupScreen);
			
			
			
					
			
			
		}
		else if (gameState.equals(EGameStates.STRATEGY)) {
			//Initialize Strategy-related GUIs via factories
			//Load relevant assets
			
		}
		else if (gameState.equals(EGameStates.COMBAT)) {
			//Initialize Combat-related GUIs via factories
			//Load relevant assets
			
		}
		
		
		
	}
	
	
	

}
